
import { Controller, Inject, Get, Query, Param, Del, Post, Put, Body } from '@midwayjs/core';
import { Auth } from "../decorator/auth.decorator";
import { ApiTags, ApiOperation, ApiResponse, ApiParam, ApiBody } from '@midwayjs/swagger';
import { BusinessType, Log } from "../decorator/log.decorator";
import { TeamService } from '@service/team.service';
import { CreateTeamDto, UpdateTeamDto, QueryTeamDto,teamTeacherDto} from '@dto/team.dto';

@ApiTags('队伍信息')
@Controller('system/team')
export class TeamController {
  @Inject()
  teamService: TeamService;
  // 创建
  @ApiOperation({ summary: '创建队伍信息', description: '创建新的队伍信息记录' })
  @ApiBody({ type: CreateTeamDto, description: '队伍信息信息数据' })
  @ApiResponse({ status: 200, description: '创建成功' })
  @Log({ title: '队伍信息-创建', businessType: BusinessType.ADD })
  @Post('/')
  async create(@Body() body: CreateTeamDto) {
    return await this.teamService.create(body);
  }
  // 获取列表
  @ApiOperation({ summary: '获取队伍信息列表', description: '分页查询队伍信息信息列表' })
  @ApiResponse({ status: 200, description: '查询成功' })
  @Log({ title: '队伍信息-列表', businessType: BusinessType.LIST })
  @Get('/list')
  async list(@Query() query: QueryTeamDto) {
    return await this.teamService.list(query);
  }
  // 获取详情
  @ApiOperation({ summary: '获取队伍信息详情', description: '根据teamId查询队伍信息详细信息' })
  @ApiParam({ name: 'teamId', description: 'teamId值' })
  @ApiResponse({ status: 200, description: '查询成功' })
  @Auth('system:team:query')
  @Log({ title: '队伍信息-详情', businessType: BusinessType.DETAIL })
  @Get('/:teamId')
  async detail(@Param('teamId') teamId: string) {
    return await this.teamService.detail(teamId);
  }
  // 修改
  @ApiOperation({ summary: '修改队伍信息', description: '根据teamId修改队伍信息信息' })
  @ApiBody({ type: UpdateTeamDto, description: '更新的队伍信息信息数据' })
  @ApiResponse({ status: 200, description: '修改成功' })
  @Log({ title: '队伍信息-修改', businessType: BusinessType.EDIT })
  @Put('/')
  async update(@Body() body: UpdateTeamDto) {
    return await this.teamService.update(body);
  }
  // 删除
  @ApiOperation({ summary: '删除队伍信息', description: '根据teamId删除队伍信息记录' })
  @ApiParam({ name: 'teamId', description: 'teamId值' })
  @ApiResponse({ status: 200, description: '删除成功' })
  @Auth('system:team:remove')
  @Log({ title: '队伍信息-删除', businessType: BusinessType.REMOVE })
  @Del('/:teamId')
  async remove(@Param('teamId') teamId: string) {
    const teamIds = teamId.split(',').map((teamId) => +teamId);
    return this.teamService.remove(teamIds);
  }

  //添加志愿
  @ApiOperation({ summary: '添加队伍志愿', description: '根据teamId添加队伍志愿' })
  @ApiBody({ type: teamTeacherDto, description: '添加的队伍志愿信息数据' })
  @ApiResponse({ status: 200, description: '添加成功' })
  @Log({ title: '队伍信息-添加志愿', businessType: BusinessType.ADD })
  @Post('/teamTeacher')
  async createTeamTeacher(@Body() body: teamTeacherDto) {
    return await this.teamService.createTeamTeacher(body);
  }

  //获取选中教师的队伍
  @ApiOperation({ summary: '获取选择当前教师的队伍', description: '根据teacherId查表' })
  @ApiParam({ name: 'teacherId', description: 'teacherId值' })
  @ApiResponse({ status: 200, description: '查询成功' })
  // @Auth('system:team:query')
  @Log({ title: '队伍信息-获取选中教师的队伍', businessType: BusinessType.DETAIL })
  @Get('/teamTeacher/:teacherId')
  async get(@Param('teacherId') teacherId: number) {
    return await this.teamService.get(+teacherId);
  }

  // 导出
  @ApiOperation({ summary: '导出队伍信息', description: '根据查询参数导出队伍信息数据' })
  @ApiBody({ type: QueryTeamDto, description: '导出查询参数' })
  @ApiResponse({ status: 200, description: '导出成功' })
  @Auth('system:team:export')
  @Log({ title: '队伍信息-导出', businessType: BusinessType.EXPORT })
  @Post('/export')
  async export(@Body() queryParams: QueryTeamDto) {
    return await this.teamService.export(queryParams);
  }


}
